package com.example.administrator.xtu_community.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.administrator.xtu_community.simpleClass.DataBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

public class ImageBannerAdapter extends BannerAdapter<DataBean,ImageBannerAdapter.ViewHoler> {

    private List<DataBean> mBeans;
    public ImageBannerAdapter(List<DataBean> mBeans){
        super(mBeans);
        this.mBeans = mBeans;
    }
    @Override
    public ViewHoler onCreateHolder(ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new ViewHoler(imageView);
    }

    @Override
    public void onBindView(ViewHoler holder, DataBean data, int position, int size) {
        holder.imageView.setImageResource(data.getImageId());
    }

    class ViewHoler extends RecyclerView.ViewHolder {

        private ImageView imageView;

        public ViewHoler(@NonNull View itemView) {
            super(itemView);
            this.imageView = (ImageView) itemView;
        }
    }
}
